package com.ciaojian.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ciaojian.core.enums.business.WorkerApplyStatusEnum;
import com.ciaojian.core.model.SchedulingExamine;
import com.ciaojian.core.model.vo.WorkerInfoVO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 排班审核表 Mapper 接口
 * </p>
 *
 * @author Atlakyn
 * @since 2021-03-30
 */
public interface SchedulingExamineMapper extends BaseMapper<SchedulingExamine> {
    SchedulingExamine insertExamine(@Param("schedulingExamine") SchedulingExamine schedulingExamine);

    /**
     * 根据门店 id 查询排班申请记录
     *
     * @param storeId 门店id
     * @param status  审核状态
     * @param page    分页插件
     * @return 排班申请记录
     */
    @Select("SELECT * FROM d_scheduling_examine" +
            " WHERE wid = #{workerId} AND status = #{status} " +
            "AND logic_del = 0 " +
            "ORDER BY create_time DESC")
    @Results({
            @Result(column = "wid", property = "worker", javaType = WorkerInfoVO.class, one = @One(select = "com.ciaojian.core.mapper.WorkerMapper.getWorkerInfoById"))
    })
    List<SchedulingExamine> findByStoreId(@Param("workerId") Integer workerId,
                                          @Param("status") WorkerApplyStatusEnum paramWorkerApplyStatusEnum,
                                          @Param("page") Page<SchedulingExamine> page);

    /**
     * 根据发型师Ids和日期查询记录
     *
     * @param workerIdList 发型师 id List
     * @param date         排班日期
     * @return 排班记录
     */
    List<SchedulingExamine> listByWorkerIdsAndDate(@Param("workerIdList") List<Integer> workerIdList, @Param("date") Date date);

    /**
     * 根据发型师Id和日期查询记录
     *
     * @param workerId 发型师Id
     * @param date     日期
     * @return 排班申请记录
     */
    @Select("SELECT * FROM d_scheduling_examine WHERE wid = #{workerId} AND date = #{date} ")
    List<SchedulingExamine> listByWorkerIdAndDate(@Param("workerId") Integer workerId, @Param("date") Date date);

}
